﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Collections.Specialized;

namespace Altairis.IisNetDiag {
    internal static class ExtensionMethods {

        public static int GetValue(this NameValueCollection c, string key, int defaultValue, int minValue, int maxValue) {
            var s = c[key];
            int i;
            if (string.IsNullOrEmpty(s) || !int.TryParse(s, out i)) return defaultValue;
            if (i < minValue || i > maxValue) return defaultValue;
            return i;
        }

        public static string GetValue(this NameValueCollection c, string key, string defaultValue) {
            var s = c[key];
            if (string.IsNullOrEmpty(s)) return defaultValue;
            return s;
        }

    }
}